<?php
namespace app\home\model;
use think\Model;

class CourseAgeModel extends Model
{
	protected $table  = 'qm_course_age_stage';


	/**
	*
	*查找某个年龄段的所有课程ID
	**/
	public function getCourseAgeIdCount($age_id)
	{
		$list = $this->where('age_stage_id', '=', $age_id)->column('course_id');
		return $list;
	}


	/**
	*某个年龄段的课程信息
	*
	**/
	public function getCourseWhereAgeId($age_stage_id, $page = 1, $field = '*')
	{
		$keys = (($page - 1) * 5);
		$limit = 5;

		$date = date('Y-m-d H:i:s');
		$where = [
			['c.status', '=', 1],
			['c.start_time', '<=', $date],
			['c.end_time', '>=', $date],
		];

		$list = $this->alias('ca')->where('ca.age_stage_id', '=', $age_stage_id)
					->where($where)
					->join('qm_course c', 'ca.course_id = c.id')->order('c.sort DESC')->limit($keys, $limit)->select();
				
		if(!empty($list))
		{
			$list = $list->toArray();
		}
		
		return $list;
	}

}
